#!/bin/bash

BINDIR=$(cd $(dirname $0) && pwd)

. ${BINDIR}/common

if [ ! -d ${LOGDIR} ]
then
	mkdir -p ${LOGDIR}
	chown ${FPPUSER}.${FPPUSER} ${LOGDIR}
	chmod 775 ${LOGDIR}
fi

FPPTZ=$(grep "TimeZone" ${MEDIADIR}/settings | cut -f2 -d\")
SYSTEMTZ=$(cat /etc/timezone)

if [ ! -z "${FPPTZ}" -a "x${FPPTZ}" != "x${SYSTEMTZ}" ]
then
    if [ -f "/usr/bin/timedatectl" ]
    then
        ${SUDO} timedatectl set-timezone ${FPPTZ}
    else
        echo ${FPPTZ} | ${SUDO} tee /etc/timezone > /dev/null
        ${SUDO} dpkg-reconfigure -f noninteractive tzdata
    fi
fi
